import StoreManager from "@/plugins/storage";
import axios from "../axios";
import type { FileInfoDTO } from "./types";
const prefix = `${import.meta.env.VITE_APP_API_URL}/file`

class FileController {
  getUploadUri() {
    return `${prefix}/upload?at=` + StoreManager.getString("access-token");
  }
  buildDownloadUri(fileId: string) {
    return `${prefix}/download?fileId=${fileId}&at=${StoreManager.getString("access-token")}`
  }
  getFileInfo(fileIds: string[]) {
    return axios.post<FileInfoDTO[]>(`${prefix}/info`, fileIds);
  }
  browserDownload(fileId: string) {
    window.open(`${prefix}/download?fileId=${fileId}&at=${StoreManager.getString("access-token")}`, "_blank");
  }
}

export default FileController;
